package view;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.OrderLine;
import model.FactoryOrder;
import model.Product;

public class OrderLineDAO {
	
	private Connection con = null;
	
	public OrderLineDAO (Connection incon)
	{
		con = incon;
	}
	
	public OrderLine viewOrderLine(FactoryOrder facOrd, Product prod)
	{
		return viewOrderLine(facOrd.getOrderId(), prod.getProductId());
	}
	
	public OrderLine viewOrderLine(long orderId, long productId)
	{
		ResultSet rs=null;
	    OrderLine outOrderLine = new OrderLine();
	    PreparedStatement ps=null;
	    
	    try{
        	ps=con.prepareStatement("select * " +
            		"from CSC342.Order_Line o" +
            		"where o.order_id =? and o.product_id =?");
            ps.setSomething(1,orderId);
            ps.setSomething(2,productId);

            rs=ps.executeQuery();
            while(rs.next())
            {
            	outOrderLine.setOrderedQuantity(rs.getBigDecimal(1));
            	outOrderLine.setorderId(rs.getBigDecimal(1));
            	outOrderLine.setproductId(rs.getBigDecimal(1));
                
                /* don't need to set parent, must be done when you instantiate the ee class (must setup past classes correctly. */
                
                System.out.println("View Person Success");
            }
	    	
	    	rs.close();
			ps.close();	
	    }
	    catch(SQLException e)
        {
            System.out.println("Error in view.OrderLineDAO.viewOrderLine" + e.getSQLState());
            System.out.println("/nError Code: " + e.getErrorCode());
            System.out.println("/nMessage: " + e.getMessage());
            System.exit( 1 );
        }
        catch(Exception e)
        {
            System.out.println("unknown Error in view.OrderLineDAO.viewOrderLine");
            System.out.println("/nMessage: " + e.getMessage());
            System.exit( 1 );
        }
	        
		return null;
	}
}
